<template>
  <div id="app" @touchstart="touchs($event)" @touchmove="touchm($event)" @click.capture="hide($event)" :style="{'overflow-y': ($children[0] ? ($children[0].close ? 'scroll' : 'hidden') : 'scroll')}">
    <Title :menus="menus" :state="tState"></Title>
    <keep-alive>
      <router-view v-on:order="order"/>
    </keep-alive>
    <Footer :state="fState"></Footer>
    <suspend :footTop="footTop"/>
    <citys :show="cshow" :type="ctype"/>
  </div>
</template>

<script>
import Title from "./components/public/Title"
import Footer from "./components/public/Footer"
import suspend from "./components/public/suspend"
import citys from "./components/public/Citys"
export default {
  name: "App",
  data() {
    return {
      menus: [
        {
          name: "首页",
          url: "/",
          img: require("./assets/home/home.png")
        },
        {
          name: "合规税筹",
          url: "/shuichou/",
          img: require("./assets/home/shuichou.png")
        },
        {
          name: "全国社保交付",
          url: "/shebao/",
          img: require("./assets/home/shebao.png")
        },
        {
          name: "残疾人就业计划",
          url: "/canji/",
          img: require("./assets/home/canji.png")
        },
        {
          name: "爱收入",
          url: "/ishouru.html",
          img: require("./assets/home/isr.png")
        },
        {
          name: "专题",
          url: "/zt/",
          img: require("./assets/home/zt.png")
        },
        {
          name: "资讯",
          url: "/news/",
          img: require("./assets/home/news.png")
        }
      ],
      scrollTop: 0,
      sTop: 0,
      tState: 1,
      fState: 1,
      footTop: 0,
      cshow: false,
      ctype: 0,
      valid: null,
      boxH: 0,
      beginY: 0
    };
  },
  mounted() {
    this.$el.addEventListener("scroll", this.scroll);
    this.valid = Array.prototype.slice.call(this.$el.children, 0, 3)
    // this.updata();
  },
  components: {
    Title,
    Footer,
    suspend,
    citys
  },
  methods: {
    touchs(e){
      this.beginY = e.touches[0].clientY
    },
    touchm(e){
      if(!this.$children[0].close && e.target && e.target.className.indexOf('tlink') < 0){
        e.preventDefault();
      }
      if(this.beginY < e.touches[0].clientY && this.sTop == 0){
        e.preventDefault()
      }
      if(this.beginY > e.touches[0].clientY && this.sTop >= this.boxH){
        e.preventDefault()
      }
    },
    hide(e) {
      if (!this.$children[0].close) {
        if(e.target && e.target.className.indexOf('tlink') < 0){
          e.stopPropagation();
        }
        this.$children[0].close = true;
      }
      if(this.cshow){
        this.cshow = false
      }
    },
    scroll() {
      if (this.scrollTop < this.$el.scrollTop) {
        this.scrollTop = this.$el.scrollTop;
      }
      this.sTop = this.$el.scrollTop;
    },
    order(a) {
      if (a.target == 'title') {
        this.tState = a.type;
      }
      if(a.target == 'footer') {
        this.fState = a.type
      }
      this.updata()
    },
    updata () {
      setTimeout(function(){
        if(getComputedStyle(this.$el.children[2])['display'] == 'none'){
          var el = this.$el.children[1].lastChild.lastChild
          if(el.className.indexOf('footer') > -1){
            this.footTop = el.offsetTop
          }
          else{
            this.footTop = null
          }
        }
        else{
          this.footTop = this.$el.children[2].offsetTop
        }
        this.$children[0].$el.scrollIntoView()
        var height = 0
        this.valid.forEach(e => {
          height += e.clientHeight
        })
        this.boxH = height - this.$el.clientHeight
      }.bind(this), 10)
    }
  }
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: arial, 'Microsoft Yahei', '微软雅黑';
}
body,
html {
  height: 100%;
}
#app {
  height: 100%;
  overflow-y: scroll;
  overflow-x: hidden;
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  /* -webkit-overflow-scrolling: touch; */
}
.mint-swipe, .mint-swipe-items-wrap{
  width: 100%;
}
.nitem {
  font-size: 0.28rem;
  color: #999;
  margin-bottom: 1.1rem;
}
.nitem > div:nth-child(1) {
  width: 1.68rem;
  height: 1.68rem;
  margin: 0.5rem 2.91rem 0;
  background-size: cover;
}
.nitem > div:nth-child(2) {
  position: relative;
  font-size: 0.32rem;
  color: #333;
  margin: 0.3rem 0 0.25rem;
  font-weight: bold;
  transition: all 0.5s;
}
.nitem > div:nth-child(3) {
  position: relative;
  transition: all 0.5s;
}
.nitem p {
  line-height: 0.36rem;
}
.mint-indicator-wrapper{
  padding: 10px 30px !important;
}
.vmcontent{
  padding: 0.3rem;
}
.vmcontent p{
  line-height: 0.4rem !important;
  text-indent: 0.55rem !important;
  font-size: 0.3rem !important;
  color: #333 !important;
  font-family: arial, 'Microsoft Yahei', '微软雅黑' !important;
}
.vmcontent span{
  font-size: 0.3rem !important;
  color: #333 !important;
  font-family: arial, 'Microsoft Yahei', '微软雅黑' !important;
}
.vmcontent img{
  width: 100%;
  float: left;
}
.ashow > div:nth-child(2) {
  top: 0rem !important;
  opacity: 1 !important;
}
.ashow > div:nth-child(3) {
  top: 0rem !important;
  opacity: 1 !important;
}
.module-mobile-cmt-float-bar {
  display: none !important;
}
</style>
